import { BaseWindow } from "../../../component/window/BaseWindow";
import { ILayer } from "../../../mvc/interfaces/ILayer";
import { Language } from "../../../../extend/language/Language";
import { ObjCreate } from "../common/ObjCreate";
import { GlobalStyle } from "../../../common/global/GlobalStyle";
import { WrestleWeekCellRenderer } from "./cellRendener/WrestleWeekCellRenderer";
import { DataProvider } from "../../../../fl/data/DataProvider";
import { FontUtil } from "../../../common/font/FontUtil";
import { Cache } from "../../cache/Cache";
import { MyWrestleInfo } from "./wrestleData/MyWrestleInfo";
import { ItemConfig } from "../../resource/ItemConfig";
import { SWrestleAccount } from "../../../../Message/Public/SWrestleAccount";
import { DateParser } from "../../../common/tools/DateParser";
import { WrestleWeekData } from "./wrestleData/WrestleWeekData";
import { GTileList } from "../../../../com/mui/controls/GTileList";
//class WrestleWeekWindom
    
    export  class WrestleWeekWindom extends BaseWindow
    {
        constructor(arg1: ILayer=null)
        {
            super(arg1);
            this.initDes();
            setSize(514, this.bgHeight + 47);
            title = Language.getString(42330);
            titleHeight = 26;
            this.addEventListener(flash.events.Event.ADDED_TO_STAGE, this.onAddToStage);
            return;
        }

        protected initDes(): void
        {
            this.rankText = Language.getString(42331);
            this.rewardTxt = Language.getString(42332);
            this.lastRankTxt = Language.getString(42333);
            this.lastRewardTxt = Language.getString(42334);
            return;
        }

        protected /* override */ createChildren(): void
        {
            super.createChildren();
            this.initDataArray();
            ObjCreate.createBg(18, 38, 247, this.bgHeight, this);
            ObjCreate.createBg(269, 38, 227, this.bgHeight, this);
            ObjCreate.createTextField(this.rankText, 50, 51, 70, 20, this, GlobalStyle.textFormat6);
            ObjCreate.createTextField(this.rewardTxt, 160, 51, 70, 20, this, GlobalStyle.textFormat6);
            this._tileList = ObjCreate.createTileList(34, 73, 224, 217, this);
            this._tileList.rowHeight = 31;
            this._tileList.columnWidth = 224;
            this._tileList.setStyle("cellRenderer", WrestleWeekCellRenderer);
            this._tileList.dataProvider = new DataProvider(this._wrestleDataArray);
            var loc1=GlobalStyle.textFormatGreen;
            loc1.size = 14;
            loc1.bold = true;
            this._tfDate = ObjCreate.createTextField("", 315, 75, 150, 20, this, loc1);
            ObjCreate.createTextField(this.lastRankTxt, 310, 117, 90, 20, this);
            ObjCreate.createTextField(this.lastRewardTxt, 310, 150, 90, 20, this);
            var loc2=GlobalStyle.textFormat6;
            loc2.font = FontUtil.EmbedNumberName;
            loc2.size = 25;
            this._tfLastRank = ObjCreate.createEmbedTextFiled("0", 402, 114, 80, 25, this, loc2);
            this._tfLastReward = ObjCreate.createTextField("", 310, 170, 120, 25, this);
            var loc3=ObjCreate.createTextField("", 305, 208, 170, 20, this, GlobalStyle.textFormatGreen);
            loc3.htmlText = Language.getString(44566);
            return;
        }

        protected onAddToStage(arg1: Object /* flash.events.Event */): void
        {
            var loc1=Cache.instance.wrestle.wrestleMyWrestleinfo;
            if (loc1) 
            {
                this.updateInfo(loc1);
            }
            var loc2=Cache.instance.wrestle.account;
            if (loc2) 
            {
                this.updateAccount(loc2);
            }
            return;
        }

        public updateInfo(arg1: MyWrestleInfo): void
        {
            var loc1=null;
            if (arg1 && arg1.ex) 
            {
                loc1 = arg1.ex;
                if (loc1.lastWeekRank != 0) 
                {
                    this._tfLastRank.embedFonts = true;
                    this._tfLastRank.text = loc1.lastWeekRank.toString();
                }
                else 
                {
                    this._tfLastRank.embedFonts = false;
                    this._tfLastRank.htmlText = "<font color=\'#B1efff\' size=\'12\'>" + Language.getString(40344) + "</font>";
                }
                if (loc1.lastWeekReward) 
                {
                    this._tfLastReward.x = 310;
                    this._tfLastReward.y = 170;
                    this._tfLastReward.htmlText = ItemConfig.instance.getInfoByCode(loc1.lastWeekReward).htmlName;
                }
                else 
                {
                    this._tfLastReward.x = 402;
                    this._tfLastReward.y = 150;
                    this._tfLastReward.text = Language.getString(40344);
                }
            }
            return;
        }

        public updateAccount(arg1: SWrestleAccount): void
        {
            this._tfDate.htmlText = DateParser.parse(arg1.weekAccountDt, Language.getString(42335));
            return;
        }

        protected initDataArray(): void
        {
            this._wrestleDataArray = [];
            this._wrestleDataArray.push(new WrestleWeekData("1", 14011942));
            this._wrestleDataArray.push(new WrestleWeekData("2", 14011943));
            this._wrestleDataArray.push(new WrestleWeekData("3", 14011944));
            this._wrestleDataArray.push(new WrestleWeekData("4-10", 14011945));
            this._wrestleDataArray.push(new WrestleWeekData("11-50", 14011946));
            this._wrestleDataArray.push(new WrestleWeekData("51-100", 14011947));
            return;
        }

        public static hasInstance(): Boolean
        {
            return !(WrestleWeekWindom._instance == null);
        }

        public static get instance(): WrestleWeekWindom
        {
            if (!WrestleWeekWindom._instance) 
            {
                WrestleWeekWindom._instance = new WrestleWeekWindom();
            }
            return WrestleWeekWindom._instance;
        }

        protected /* var */_wrestleDataArray: Array<any>;

        protected /* var */_tileList: GTileList;

        protected /* var */_tfDate: Object /* flash.text.TextField */;

        protected /* var */_tfLastRank: Object /* flash.text.TextField */;

        protected /* var */_tfLastReward: Object /* flash.text.TextField */;

        protected /* var */bgHeight: number=226;

        protected /* var */rankText: string;

        protected /* var */rewardTxt: string;

        protected /* var */lastRankTxt: string;

        protected /* var */lastRewardTxt: string;

        /* internal */ static /* var */_instance: WrestleWeekWindom;
    }
